/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package example.verify.custom;

import picounit.features.verify.Evaluator;
import picounit.features.verify.ExtensibleStringConstraints;
import picounit.features.verify.constraint.ModifiableConstraint;
import picounit.features.verify.constraint.Modifier;
import picounit.features.verify.constraint.StringCaseModifier;
import picounit.verify.ReasonCapturer;

public class CustomStringConstraints extends ExtensibleStringConstraints
	implements CustomStringConstraintsStage {

	public CustomStringConstraints(Evaluator evaluator) {
		super(evaluator);
	}
	
	public CustomStringConstraintsStage ignoringCase() {
		setModifier(StringCaseModifier.INSTANCE);
		
		return this;
	}

	public ReasonCapturer isOfLength(int length) {
		return passes(new StringOfLengthConstraint(length));
	}

	public ReasonCapturer isAPalindrome() {
		return passes(new IsPalindrome());
	}

	public ReasonCapturer isEqualToBOOM() {
		return passes(new EqualToBOOM(modifier()));
	}
	
	private final class EqualToBOOM extends ModifiableConstraint<EqualToBOOM> {
		private EqualToBOOM(Modifier modifier) {
			super(modifier);
		}

		@Override
		public boolean evaluate(Object value) {
			return modify(value).equals(modify("BOOM"));
		}

		@Override
		public String describeFailureImpl() {
			return "does not equal <BOOM>";
		}
	}
}